package com.lqe.study.Servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

@WebServlet("/ServletDemo04")
public class ServletDemo04 extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req,resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

            InputStream resourceAsStream1 = ServletDemo04.class.getClassLoader().getResourceAsStream("/db.properties");
            System.out.println(resourceAsStream1);
            InputStream resourceAsStream = this.getServletContext().getResourceAsStream("WEB-INF/classes/db.properties");
            System.out.println(resourceAsStream);
            Properties prop = new Properties();
            prop.load(resourceAsStream);
            String username = prop.getProperty("username");
            String password = prop.getProperty("password");
            System.out.println(username+"&&"+password);
            resp.getWriter().println(username+"&&"+password);

    }
}


